package com.ellricky.baselib.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.andr.common.ui.dialog.BaseDialog;
import com.andr.common.util.EmptyUtil;
import com.ellricky.baselib.R;
import com.ellricky.baselib.listener.OnTakePhotoListener;

public class TakePhotoDialog extends BaseDialog {

    private String firstText;
    private String secondText;
    private String thirdText;
    private String fourthText;
    private String fifthText;

    private String cancelText;

    private TextView tvFirst;
    private TextView tvSecond;
    private TextView tvThird;
    private TextView tvFourth;
    private TextView tvFifth;

    private TextView tvCancel;

    public void setListener(OnTakePhotoListener listener) {
        this.listener = listener;
    }

    private OnTakePhotoListener listener;

    @Override
    public int getCustomLayoutId() {
        return R.layout.dialog_take_camera;
    }

    public TakePhotoDialog(Context context) {
        super(context);
        setSizeWidth(WindowManager.LayoutParams.MATCH_PARENT);
        setAnimationStyle(R.style.BottomDialog);
        setGravity(Gravity.BOTTOM);
    }


    @Override
    public void initWidgets() {

        tvFirst = findViewById(R.id.tv_first);
        tvSecond = findViewById(R.id.tv_second);
        tvThird = findViewById(R.id.tv_third);
        tvFourth = findViewById(R.id.tv_fourth);
        tvFifth = findViewById(R.id.tv_fifth);

        tvCancel = findViewById(R.id.tv_cancel);

        if (tvFirst != null) {
            tvFirst.setText(firstText);
            tvFirst.setOnClickListener(this);
        }

        if (tvSecond != null) {
            if (!EmptyUtil.isEmpty(secondText)) {
                tvSecond.setVisibility(View.VISIBLE);
                tvSecond.setText(secondText);
                tvSecond.setOnClickListener(this);
            } else {
                tvSecond.setVisibility(View.GONE);
            }
        }

        if (tvThird != null) {
            if (!EmptyUtil.isEmpty(thirdText)) {
                tvThird.setVisibility(View.VISIBLE);
                tvThird.setText(thirdText);
                tvThird.setOnClickListener(this);
            } else {
                tvThird.setVisibility(View.GONE);
            }
        }

        if (tvFourth != null) {
            if (!EmptyUtil.isEmpty(fourthText)) {
                tvFourth.setVisibility(View.VISIBLE);
                tvFourth.setText(fourthText);
                tvFourth.setOnClickListener(this);
            } else {
                tvFourth.setVisibility(View.GONE);
            }
        }

        if (tvFifth != null) {
            if (!EmptyUtil.isEmpty(fifthText)) {
                tvFifth.setVisibility(View.VISIBLE);
                tvFifth.setText(fifthText);
                tvFifth.setOnClickListener(this);
            } else {
                tvFifth.setVisibility(View.GONE);
            }

        }


        if (tvCancel != null) {
            if (TextUtils.isEmpty(cancelText)) {
                tvCancel.setText(R.string.common_dialog_cancel);
            } else {
                tvCancel.setText(cancelText);
            }
            tvCancel.setOnClickListener(this);
        }
    }


    @Override
    public void onClickView(View v) {

        if (listener == null) return;

        dismiss();

        if (v == tvFirst) {
            listener.onClickItem(this, 0);
            return;
        }

        if (v == tvSecond) {
            listener.onClickItem(this, 1);
        }

        if (v == tvThird) {
            listener.onClickItem(this, 2);
        }
        if (v == tvFourth) {
            listener.onClickItem(this, 3);
        }
        if (v == tvFifth) {
            listener.onClickItem(this, 4);
        }

    }


    public void setFirstText(String firstText) {
        this.firstText = firstText;
    }

    public void setFirstText(int res) {
        this.firstText = context.getString(res);
    }

    public void setSecondText(String secondText) {
        this.secondText = secondText;
    }

    public void setSecondText(int res) {
        this.secondText = context.getString(res);
    }

    public void setCancelText(String cancelText) {
        this.cancelText = cancelText;
    }

    public void setCancelText(int res) {
        this.cancelText = context.getString(res);
    }

    public void setThirdText(String thirdText) {
        this.thirdText = thirdText;
    }

    public void setThirdText(int res) {
        this.thirdText = context.getString(res);
    }

    public void setFourthText(String fourthText) {
        this.fourthText = fourthText;
    }

    public void setFourthText(int res) {
        this.fourthText = context.getString(res);
    }

    public void setFifthText(String fifthText) {
        this.fifthText = fifthText;
    }

    public void setFifthText(int res) {
        this.fifthText = context.getString(res);
    }
}
